package ch.zhaw.swp1.util;

import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

import ch.zhaw.swp1.model.message.MessageType;
import ch.zhaw.swp1.model.message.address.Address;
import ch.zhaw.swp1.model.message.address.EmailAddress;
import ch.zhaw.swp1.model.message.address.MMSAddress;
import ch.zhaw.swp1.model.message.address.PrintAddress;
import ch.zhaw.swp1.model.message.address.SMSAddress;

/**
 * Helper class to do various tasks 
 * @author Daniel Tiefenauer
 */
public class MultiChannelParser {
	
	/**
	 * Parse a string of recipients entered by the user.
	 * @param recipients the recipients entered by the user
	 * @return a list of adresses the message should be sent to
	 */
	public static List<Address> parseRecipients(String recipients, MessageType type) {
		List<Address> recipientList = new ArrayList<Address>();
		StringTokenizer st = new StringTokenizer(recipients, ";");
		
		while(st.hasMoreTokens()){
			Address address = null;
			switch(type){
			case EMAIL: address = new EmailAddress(st.nextToken()); break;
			case SMS: address = new SMSAddress(st.nextToken()); break;
			case MMS: address = new MMSAddress(st.nextToken()); break;
			case PRINT: address = new PrintAddress(st.nextToken()); break;
			}
			recipientList.add(address);
		}
		
		return recipientList;
	}

}
